﻿{% extends "base.html" %}

{% block breadcrumb %}
    {{ block.super }}
    {% load breadcrumb_tags %}

    {% if not user.userprofile.isSchool %}
        {% add_crumb 'Báo cáo' 'department_report' %}
        {% add_crumb request.session.school_name 'report' request.session.school_id %}
    {% else %}
        {% add_crumb 'Báo cáo' 'report' %}
    {% endif %}

    {% if type == 1 %}
        {% add_crumb 'Điểm trung bình' %}
    {% else %}
        {% if type == 2 %}
            {% add_crumb 'Điểm thi cuối kì' %}
        {% endif %}
    {% endif %}
{% endblock %}

{% block js %}
    <script>
        $(document).ready(function () {
            function changeTerm() {
                $('#subject').val('-1');
            }

            $('#term').change(function () {
                changeTerm();
            })
            $('#subject').change(function () {
                var termNumber = $('#term').val();
                var subjectIndex = $('#subject').val();
                var modeView = $('#modeView').val();
                if (subjectIndex != '-1')
                    window.location.href = "/school/report/count2/" + {{type}}+'/' + modeView + '/' + {{year_id}} +
                            "/" + termNumber + '/' + subjectIndex;
            })

            $('#modeView').change(function () {
                $('#subject').val("-1");
            });
            $('#term').val("{{number}}");
            $('#modeView').val("{{modeView}}");
            $('#subject').val("{{index}}");
        });

    </script>
{% endblock %}

{% block css %}
    <link href="/static/css/report.css" rel="stylesheet">
{% endblock %}

{% block content %}

    <div class="form-inline pagination-centered ">
        <label>Học kỳ</label>
        <select id="term" class="input-medium">
            <option value='1'> Học kỳ I</option>
            <option value='2'> Học kỳ II</option>
            {% if type == 1 %}
                <option value='3'> Cả năm</option>
            {% endif %}
        </select>

        <label>Thống kê theo</label>
        <select id="modeView" class="input-medium">
            <option value='1'>Lớp</option>
            <option value='2'>Giáo viên</option>
        </select>

        <label>Môn</label>
        <select id="subject" class="input-medium">
            <option value="-1"> Chọn môn</option>
            {% for s in subjectList %}
                <option value="{{forloop.counter}}"> {{ s }} </option>
            {% endfor %}
        </select>

        {% if index != -1 %}
            <a href="{% url count2 type modeView year_id number index 1 %}" class="btn pull-right">
                Xuất ra Excel
            </a>
        {% endif %}
    </div>


    {% if index != -1 %}
        <table width="100%" class="table table-bordered grid">
            <thead>
            <tr>
                <th rowspan=2 width="12%" class="align-left" >
                    Lớp
                </th>
                <th rowspan=2 width="6%" class="align-center">
                    Sĩ Số
                </th>
                <th rowspan=2 width="18%" class="align-left">
                    Giáo viên giảng dạy
                </th>
                {% for h in headerTable %}
                    <th colspan=2>
                        {{ h }}
                    </th>
                {% endfor %}
            </tr>
            <tr>
                {% for h in headerTable %}
                    <th width="6%" title="Số lượng">
                        <span class="align-center">SL</span>
                    </th>
                    <th width="6%" title="Phần trăm">
                        <span class="align-center">%</span>
                    </th>
                {% endfor %}
            </tr>
            </thead>
            <tbody>
            {% for b,sum,total,list1 in list %}
                {% for name,ss,teacherName,l in list1 %}
                    <tr>
                        <td class="align-left">
                            {{ name }}
                        </td>

                        <td align="center">
                            <span class="align-center">{{ ss|floatformat:"0" }}</span>
                        </td>
                        <td class="align-left">
                            {{ teacherName }}
                        </td>
                        {% for u,v in l %}
                            <td>
                                {{ u }}
                            </td>

                            <td>
                                {{ v|floatformat:"2" }}
                            </td>
                        {% endfor %}
                    </tr>
                {% endfor %}
                <tr class="subtotal-row">
                    <td>
                        {#Khối {{ b.number }} #}
                        {{ b }}
                    </td>
                    <td align="center">
                        {{ sum|floatformat:"0" }}
                    </td>
                    <td>
                    </td>
                    {% for sl,pt in total %}
                        <td>
                            {{ sl }}
                        </td>
                        <td>
                            {{ pt|floatformat:"2" }}
                        </td>
                    {% endfor %}
                </tr>
                {#                <tr class='lastblock'>#}
                {#                    <td> &nbsp</td>#}
                {#                    <td> &nbsp</td>#}
                {#                    <td> &nbsp</td>#}
                {#                    {% for sl,pt in total %}#}
                {#                        <td> &nbsp</td>#}
                {#                        <td> &nbsp</td>#}
                {#                    {% endfor %}#}
                {#                </tr>#}
            {% endfor %}
            <tr class="total-row">
                <td>
                    Toàn trường
                </td>
                <td align="center">
                    {{ sumsumsum|floatformat:"0" }}
                </td>
                <td>&nbsp</td>
                {% for sl,pt in allList %}
                    <td>
                        {{ sl }}
                    </td>
                    <td>
                        {{ pt|floatformat:"2" }}
                    </td>
                {% endfor %}
            </tr>
            </tbody>
        </table>
    {% endif %}
{% endblock %}